#ifndef RKYOLOV8_SEG_H
#define RKYOLOV8_SEG_H

#include "rknn_api.h"

#include "opencv2/core/core.hpp"
#include "preprocess.h"
#include "opencl_accelerate.hpp"
static void dump_tensor_attr(rknn_tensor_attr *attr);
static unsigned char *load_data(FILE *fp, size_t ofst, size_t sz);
static unsigned char *load_model(const char *filename, int *model_size);
static int saveFloat(const char *file_name, float *output, int element_size);

class rkYolov8_seg
{
private:
    int ret;
    std::mutex mtx;
    std::string model_path;
    unsigned char *model_data;

    rknn_app_context_t rknn_app_ctx;
    rknn_context ctx;
    rknn_input_output_num io_num;

    rknn_tensor_attr *input_attrs;
    rknn_tensor_attr *output_attrs;
    rknn_input inputs[1];
    char *labels[OBJ_CLASS_NUM];

    std::vector<float> out_scales;
    std::vector<int32_t> out_zps;

    int channel, width, height;

    float nms_threshold, box_conf_threshold;
public:
    object_detect_result_list od_results;
    rkYolov8_seg(const std::string &model_path);
    int init(rknn_context *ctx_in, bool isChild);
    rknn_context *get_pctx();
    void drawBoxes(cv::Mat& orig_img, const object_detect_result_list& od_results);
    const char *coco_cls_to_name(int cls_id);
    cv::Mat infer(cv::Mat &ori_img);
    ~rkYolov8_seg();
};

#endif